package com.lagou.sqlSession;

import com.lagou.config.XMLConfigBuilder;
import com.lagou.config.XMLMapperBuilder;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * description SqlSessionFactoryBuilder
 * author wy
 * date 2021-04-06 23:17
 **/
public class SqlSessionFactoryBuilder
{
    public SqlSessionFactory build(InputStream in) throws DocumentException, PropertyVetoException
    {
        //第⼀：使⽤dom4j解析配置⽂件，将解析出来的内容封装到Configuration和MappedStatement中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);

        //第⼆：创建SqlSessionFactory的实现类DefaultSqlSession
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return defaultSqlSessionFactory;
    }
}
